package com.wbw.ssb.controller;

import com.wbw.ssb.common.api.CommonResult;
import com.wbw.ssb.dto.GranaryDto;
import com.wbw.ssb.mbg.entity.Granary;
import com.wbw.ssb.mbg.entity.System;
import com.wbw.ssb.service.GranaryService;
import com.wbw.ssb.service.SystemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: guibo
 * @Description:
 * @Date: Created in 15:00 2021/5/25
 * @Modified By:
 */
@RestController
@Api(tags = "粮仓管理")
@RequestMapping("/granary")
public class GranaryController {

    @Autowired
    GranaryService granaryService;

    @PostMapping(value = "/list")
    @ApiOperation("粮仓列表")
    @PreAuthorize("hasAnyAuthority('管理员','员工')")
    CommonResult<List<GranaryDto>> list(@RequestBody(required = false) Granary granary){
        return CommonResult.success(granaryService.list(granary));
    }

    @PutMapping(value = "/update")
    @ApiOperation("更新粮仓")
    @PreAuthorize("hasAnyAuthority('管理员')")
    CommonResult<Integer> update(@RequestBody Granary granary){
        return CommonResult.success(granaryService.update(granary));
    }

    @PostMapping(value = "/add")
    @ApiOperation("添加粮仓")
    @PreAuthorize("hasAnyAuthority('管理员')")
    CommonResult<Integer> add(@RequestBody Granary granary){
        return CommonResult.success(granaryService.add(granary));
    }


    @DeleteMapping(value = "/delete")
    @ApiOperation("删除粮仓")
    @PreAuthorize("hasAnyAuthority('管理员')")
    CommonResult<Integer> delete(@RequestParam List<Long> ids){
        return CommonResult.success(granaryService.delete(ids));
    }


}
